package com.ssyt.yt1.day27;

/**
 * 判断线程是否活着
 *
 * @author Hsu.
 * @since 2015年12月31日
 */
public class ThreadIsAliveDemo extends Thread {

	@Override
	public void run() {
		System.out.println("Sub Thread:" + this.getName());
	}

	public static void main(String[] args) throws InterruptedException {
		ThreadIsAliveDemo threadIsAliveDemo = new ThreadIsAliveDemo();
		// false：线程有了，但未启动
		System.out.println(threadIsAliveDemo.isAlive());

		// true：线程启动了，处于存活状态
		threadIsAliveDemo.start();
		System.out.println(threadIsAliveDemo.isAlive());

		for (int i = 0; i < 10; i++) {
			System.out.println("Main Thread:"
					+ Thread.currentThread().getName());
		}

		// true :子线程执行未完
		// false : 子线程已经执行完成
		System.out.println(threadIsAliveDemo.isAlive());
	}
}
